/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package verins.DAO;


import verins.beans.Ubigeoxprocesoelectoral;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
/**
 *
 * @author yi
 */
public class TipoParticipanteXProcesoDAO {
    
    
    
    public boolean saveAll(List <Ubigeoxprocesoelectoral> ubigeoxPe){
      try{
        // Create the EntityManager
        Ubigeoxprocesoelectoral ubigeo;
                     
               Iterator it=ubigeoxPe.iterator();

          
               while(it.hasNext()){
               ubigeo=(Ubigeoxprocesoelectoral)it.next();
               save(ubigeo);
             
               }
        
        
        
       ;
        return true;
      }catch(Exception ex){
         // JOptionPane.showMessageDialog(null, "Error al grabar datos"+ex.getMessage());
          return false;
      }
    }
    
    public boolean save(Ubigeoxprocesoelectoral ubigeoxPe){
      try{
        // Create the EntityManager
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("verinsPU");
        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();
        em.merge(ubigeoxPe);
        em.getTransaction().commit();
        em.close();
        emf.close();
        return true;
      }catch(Exception ex){
          //JOptionPane.showMessageDialog(null, "Error al grabar datos"+ex.getMessage());
          return false;
      }
    }
    
     public List findAll(int id){
        List lista=null;
        
        try{
            
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("verinsPU");
            EntityManager em = emf.createEntityManager();
           
            Query query=(Query) em.createQuery("SELECT e FROM Ubigeoxprocesoelectoral e WHERE e.ubigeoxprocesoelectoralPK.idprocesoelectoral = ?1") ;
            query.setParameter(1, id);
            lista=query.getResultList();
            
            
            em.close();    
            emf.close();
            
            return lista;
            
        }catch(Exception ex){
            System.out.println(ex.getMessage());
        }
        return lista;
    }
    
    
    
    
}
